#!bin/bash


function mysql_init() {

	/usr/local/mysql-8.0.20/support-files/mysql.server stop
	rm -rf /data/mysql/data/*
	cp -a /home/tpccdata/* /home/data/mysql/data
	/usr/local/mysql-8.0.20/support-files/mysql.server start	
}

function feature_testing() {

	for i in {0..4}
	do
		echo "change seep DELTA value:" ${seep_usage[$i]};
		sed -i "s/^#.*DELTA.*/#define DELTA $i/g" /home/wuhaotian/gov_test/kernel/drivers/cpufreq/cpufreq_seep.c
		sh /root/reset_seep.sh
		cpupower frequency-set -g seep

		for j in {0..5}
		do
			sh start_benchmark.sh &

		done

	done
}


ssh arm1 > /dev/null 2> &1<<eeooff
cd /home/shy/benchmarksql5.0-for-mysql/run
cp props.conf.bak props.conf
echo "terminals="${load_level[i]} >> /home/shy/benchmarksql5.0-for-mysql/run/props.conf
sleep 5
mkdir -p /home/shy/terminal${load_level[i]}
sh ./powertool.sh collect 1 &
./runBenchmark.sh props.conf > /home/shy/terminal${load_level[i]}/result.txt

kill -9 `ps -ef | grep powertool.sh | grep -v grep | awk '{print $2}'`

score=`cat result.txt |grep NewOrders|awk '{print $11}'`
start_day=`cat result.txt |grep Start|awk '{print $10}'|awk -F '-' '{print $2"."$3}'`
start_time=`cat result.txt |grep Start|awk '{print $11}'`
end_day=`cat result.txt |grep End|awk '{print $10}'|awk -F '-' '{print $2"."$3}'`
end_time=`cat result.txt |grep End|awk '{print $11}'`

power=`./powertool.sh avg $start_day $start_time $end_day $end_time | grep "Sys_Average_Watt"`

cd /home/shy/terminal${load_level[i]}
echo $power $score >> power.txt 
rm -rf result.txt 

eeooff
exit
echo "mysql benchmark start ok"


load_level=("300" "100" "50" "20" "10" "5");
seep_usage=("100" "80" "50" "30" "10");


mysql_init;
feature_testing;